<template>
	<view class="content" :style="{ paddingTop: totalheight }">
		<view class="bar" :style="{height:totalheight}"></view>
		<view class="head" :style="{ paddingTop: navBarHeight }">
			<view class="head-np">
				<image @click="back()" class="back" src="@/static/img/chat-09.png" mode="widthFix"></image>
				<!-- <uni-icons class="back" type="left" size="30" color="white"></uni-icons> -->
				<view class="title">商品详情</view>
			</view>
		</view>
		<swiper class="swiper" circular autoplay>
			<swiper-item  :key="i">
				<image :src="info.goodsCoverImg" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="info">
			<p class="info_price">{{info.goodsPrice}} USDA</p>
			<p class="info_name">{{info.goodsName}}</p>
			<p class="info_text">{{info.goodsTitle}}</p>
		</view>
		<view class="detail">
			<p class="title">商品详情</p>
			<view v-for="item in info.detailImgList">
				<image :src="item" mode="widthFix"></image>
			</view>
			<!-- <rich-text :nodes="info.description"></rich-text> -->
		</view>
		<view class="down">
			<view class="btn" @click="open()">立即兑换</view>
		</view>
		<uni-popup ref="popup">
			<view class="box">
				<image src="@/static/img/browse_bg2.png" mode="widthFix"></image>
				<view class="box_title">确认<text>兑换</text>吗？</view>
				<view class="box_u">
					<text>需消耗USDA</text>
					<text>{{info.goodsPrice}}</text>
				</view>
				<view class="box_s">
					<image src="@/static/img/browse_img6.png" mode="widthFix"></image>
					<text>{{walletInfo.usdtBalance}}</text>
				</view>
				<view class="box_text">手机号：{{userInfo.phone}}</view>
				<!-- <input type="number" placeholder="请输入手机号" v-model="" disabled="true"
					class="theme-ipt-bg"> -->
				<view class="box_text">钱包密码</view>
				<input type="text" placeholder="请输入钱包密码" :password="true" v-model="password"
					class="theme-ipt-bg">
				<view class="box_btn">
					<view @click="close()" class="btn_1">取消</view>
					<view @click="buy()" class="btn_2">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getWalletInfoApi,
		getByGoodsId,
		exchangeGoodsExchange,
		getMeUserAPI
	} from '@/api/api.js'
	import navBarMixin from '@/mixin/navBarMixin.js'
	export default {
		mixins: [navBarMixin],
		data() {
			return {
				id: '',
				imgList: [],
				info: '',
				unique: '',
				barshow: false,
				walletInfo: "",
				phone: "",
				password: "",
				userInfo: '',
			}
		},
		onLoad(e) {
			this.id = e.id
			this.details()
			this.getMeUserInfo()
		},
		onShow() {
			this.getWallinfo()
		},
		methods: {
			// 获取本人信息
			async getMeUserInfo() {
				const res = await getMeUserAPI()
				if (!res.code) {
					this.userInfo = res.data
				}
			},
			buy() {
				// const phoneReg = /^[1][3-9]\d{9}$/;
				// // 获取输入框的值
				// const inputValue = this.phone;
				// // 使用正则表达式进行匹配
				// const isPhoneValid = phoneReg.test(inputValue);
				// if (!isPhoneValid) {
				// 	uni.showToast({
				// 		title: "请输入正确的手机号",
				// 		icon: "none",
				// 		duration: 1000
				// 	});
				// 	return;
				// }
				exchangeGoodsExchange({
					goodsId: this.id,
					password: this.password,
					phone:this.userInfo.phone
				}).then(res=>{
					this.close()
					console.log(res);
					if(res.code==0) {
						uni.showToast({
							title:'兑换成功！',
							icon:'none',
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 2000);
						// uni.navigateTo({
						// 	url: '/pages/me/extractveTem?type=19'
						// })
					}else {
						uni.showToast({
							title:res.message,
							icon:'none',
						})
					}
				})
			},
			details() {
				getByGoodsId({
					goodsId: this.id
				}).then(res => {
					console.log(res);
					if(res.code==0) {
						this.info = res.data
					}
				})
			},
			async getWallinfo() {
				const res = await getWalletInfoApi()
				if (!res.code) {
					this.walletInfo = res.data
				}
			},
			back() {
				uni.navigateBack()
			},
			open() {
				this.$refs.popup.open('center')
			},
			close() {
				this.$refs.popup.close()
			},
		},
		onPageScroll(e) {
			// console.log(e);
			if (e.scrollTop > 30) {
				this.barshow = true
			} else {
				this.barshow = false
			}
		},
	}
</script>

<style scoped lang="less">
	.content {
		overflow: hidden;
		background-color: white;
		padding-bottom: 50rpx;
		position: relative;
		width: 100vw;
		// height: 100vh;
		// background: url('@/static/img/browse_bg.png') no-repeat;
		background-size: contain;
		padding-bottom: 126rpx;
		background-color: #F8F8F8;
	}

	.bar {
		width: 100vw;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 22;
		animation: bg 0.8s 1 both linear;
		// background-color: #B1DBFE;
		
		background: linear-gradient(to bottom left, #B8D7FF 1%, #ffffff 99%);
	}

	.head {
		position: fixed;
		top: 0;
		z-index: 33;
		width: 100%;

		.head-np {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 96rpx;
			padding: 0 30rpx;
			// box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(50, 50, 50, 0.1);
			box-sizing: border-box;
			position: relative;

			.title {
				font-size: 36rpx;
				font-weight: bold;
			}

			.back {
				width: 20rpx;
				position: absolute;
				left: 30rpx;
			}

		}
	}

	.swiper {
		width: 100%;
		height: 648rpx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
	}

	.info {
		margin: 30rpx;

		font-size: 28rpx;

		.info_price {
			font-weight: 700;
			font-size: 42rpx;
			color: #FF3535;
		}

		.info_name {
			margin-top: 16rpx;
		}

		.info_text {
			margin-top: 16rpx;
			color: #666666;
			font-size: 24rpx
		}
	}

	.detail {
		text-align: center;

		.title {
			font-style: 32rpx;
			border-top: 2rpx solid #EEEEEE;
			padding: 30rpx 0;
			margin: 30rpx 30rpx 0;
		}

		image {
			width: 100%;
			/* height: 100%; */
		}
	}

	.down {
		width: 100%;
		height: 126rpx;
		background-color: white;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.btn {
		width: 615rpx;
		height: 84rpx;
		background: #3F93FF;
		border-radius: 42rpx 42rpx 42rpx 42rpx;
		font-weight: 500;
		line-height: 84rpx;
		color: white;
		font-size: 30rpx;
		text-align: center;
	}

	.box {

		width: 600rpx;
		height: 750rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		background: #fff;
		// background: url('../../static/img/me-32.png') no-repeat;
		background-size: contain;
		// overflow: hidden;
		position: relative;

		>image {
			width: 600rpx;
			position: absolute;
			top: -80rpx;
			left: 0;
			z-index: 0;
		}

		.theme-ipt-bg {
			padding: 0 20rpx;
			margin-top: 20rpx;
			background: #F7F7F7;
		}

		.box_title {
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
			text-align: center;
			padding-top: 130rpx;
			position: relative;
			z-index: 5;

			text {
				color: #FF453A;
			}
		}

		.box_u {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-bottom: 20rpx;
			margin: 60rpx 40rpx 0;
			border-bottom: 1rpx solid #EEEEEE;
		}

		.box_s {
			margin: 10rpx 40rpx 0;
			display: flex;
			justify-content: flex-end;

			image {
				width: 34rpx;
				margin-right: 10rpx;
			}

			text {
				font-size: 25rpx;
				color: #FF453A;
			}
		}

		.box_text {
			font-size: 28rpx;
			margin: 36rpx 40rpx 10rpx 40rpx;
		}

		input {
			// background-color: #F7F7F7;
			height: 64rpx;
			line-height: 64rpx;
			background: #F4F4F4;
			border-radius: 6rpx;
			padding: 0 30rpx;
			margin: 0 40rpx;
			font-size: 26rpx;
		}

		.box_btn {
			display: flex;
			justify-content: space-between;
			margin: 50rpx 52rpx 0;

			view {
				width: 200rpx;
				line-height: 76rpx;
				text-align: center;
			}

			.btn_1 {
				border: 2rpx solid #3F93FF;
				border-radius: 40rpx;
				color: #3F93FF;
			}

			.btn_2 {
				border-radius: 40rpx;
				background: #3F93FF;
				color: #fff;
			}
		}
	}
</style>